<?php
namespace Home\Controller;
use Think\Controller;
use Common\Org\ValidationCodeOrg;
class IndexController extends Controller{
    public function index(){
		$action=$_GET["action"];
		if($action=='login'){
			$admin=D("Admin");
			$username=trim($_POST["username"]);
			$password=md5(trim($_POST["password"]));
			$vdcode=trim(strtoupper($_POST["vdcode"]));
			if($username!="" && $password!="" && $vdcode!=""){
				if($vdcode!=$_SESSION["imgcode"]){
					echo "<script>alert('您输入的验证码不正确!');history.go(-1)</script>";
				}else{
					$arr=$admin->query("select a.adminname,a.password from __ADMIN__ as a where a.adminname='%s' and a.password='%s'",array($username,$password));
					if($arr[0]["adminname"]==$username && $arr[0]["password"]==$password){
						$_SESSION["adminname"]=$arr[0]["adminname"];
						$_SESSION["loginjk"]=1;
						header("location: ".__MODULE__."/Default/");
						exit;
					}else{
						echo "<script>alert('您输入的用户名或密码不正确');location.href='".__CONTROLLER__."'</script>";
						exit;
					}
				}
			}

		}

        $this->display();
    }

	//验证码
	public function chkcode(){
		$image = new ValidationCodeOrg(60,26,4);
		$image->showImage();
		$_SESSION["imgcode"] =strtoupper($image->getCheckCode());
	}
}
